var util = require('../../utils/util.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    Info: {},
    isSubmitInfo: 1,
    tag: "",
    url: "",
    iteminfo: {},
    ordescId: 0,
    resumeurl: "https://www.tiaonali.com/tnl-candidate/wechat/candidate/order/myOrdetailResume.page",
    interviewurl: "https://www.tiaonali.com/tnl-candidate/wechat/candidate/order/myOrdetailInterview.page",
    salaryurl: "https://www.tiaonali.com/tnl-candidate/wechat/candidate/order/myOrdetailSalary.page",
    planurl: "https://www.tiaonali.com/tnl-candidate/wechat/candidate/order/myOrdetailPlan.page",
    leaveurl: "https://www.tiaonali.com/tnl-candidate/wechat/candidate/order/myOrdetailLeave.page",
    evaInfo: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var orderId = options.orderId;
    var that = this;
    this.getInfo(orderId);
    this.getOrderResume(orderId);
    util.post(app.api.selectEvaByOrderId, {
      orderId: orderId
    }, function (res) {
      console.log(res.data);
      that.setData({
        evaInfo: res.data
      })
    })
  },
  onShow: function () {

  },
  // 获取订单信息,咨询师信息
  getInfo: function (orderId) {
    var that = this;
    util.post(app.api.getOrderedById, {
      orderId: orderId
    }, function (res) {
      console.log(res.data);
      that.setData({
        Info: res.data,
      })
    })

  },

  getOrderResume: function (orderId) {
    debugger;
    var that = this;
    util.post(app.api.isHaveSubmitInfo, {
      orderId: orderId
    }, function (res) {
      that.setData({
        isSubmitInfo: res.data,
      })
    })
  },
  //确认完成该订单
  comfirmTap: function (event) {
    var that = this;
    var formId = event.detail.formId;
    var orderId = event.currentTarget.dataset.id;
    wx.showModal({
      title: '完成订单',
      content: '请确认该订单已完成',
      cancelText: '取消',
      cancelColor: '#999',
      confirmText: '确认',
      confirmColor: '#4990E2',
      success: function (res) {
        if (res.confirm) {
          app.loading();
          util.post(app.api.updateOrder, {
            formid: formId,
            orderid: orderId,
            status: 3
          }, function (res) {
            if (res.code == "200") {
              // 订单完成
              wx.showToast({
                title: '订单已完成',
                icon: 'success',
                duration: 2000
              })
              wx.navigateTo({
                url: "/pages/addCommen/addCommen?orderId=" + orderId,
              })
            }
          });
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  //猎头详细信息
  hunterTap: function (event) {
    var id = event.currentTarget.dataset.id; // 当前id
    console.log("猎头详情id获取=" + id)
    // 切换页面
    wx.navigateTo({
      url: '/pages/hunter-detail/hunter-detail?hunterid=' + id
    });
  },
  //前往评价
  gocommentTap: function (event) {
    var orderId = event.currentTarget.dataset.id; // 当前id
    wx.navigateTo({
      url: "/pages/addCommen/addCommen?orderId=" + orderId,
    })
  },
  gocompleteTap: function (event) {
    var that = this;
    var orderId = event.currentTarget.dataset.id; // 当前id
    var tag = event.currentTarget.dataset.tag
    console.log("pay success orderId=" + orderId);

    console.log("pay success tag=" + tag);
    if (tag.indexOf("简历修改") >= 0) {
      console.log("pay success url=" + that.data.resumeurl);
      wx.navigateTo({
        url: '/pages/my-ordetail-resume/web-view?orderId=' + orderId + '&url=' + encodeURIComponent(that.data.resumeurl)
      })
    } else if (tag.indexOf("面试辅导") >= 0) {
      console.log("pay success url=" + that.data.interviewurl);
      wx.navigateTo({
        url: '/pages/my-ordetail-resume/web-view?orderId=' + orderId + '&url=' + encodeURIComponent(that.data.interviewurl)
      })

    } else if (tag.indexOf("薪酬分析") >= 0) {
      console.log("pay success url=" + that.data.salaryurl);
      wx.navigateTo({
        url: '/pages/my-ordetail-resume/web-view?orderId=' + orderId + '&url=' + encodeURIComponent(that.data.salaryurl)
      })
    } else if (tag.indexOf("职业规划") >= 0) {
      console.log("pay success url=" + that.data.planurl);
      wx.navigateTo({
        url: '/pages/my-ordetail-resume/web-view?orderId=' + orderId + '&url=' + encodeURIComponent(that.data.planurl)
      })
    } else if (tag.indexOf("离职咨询") >= 0) {
      console.log("pay success url=" + that.data.leaveurl);
      wx.navigateTo({
        url: '/pages/my-ordetail-resume/web-view?orderId=' + orderId + '&url=' + encodeURIComponent(that.data.leaveurl)
      })
    }
  },
  PriceDiffTap: function (event) {
    var that = this;
    var formId = event.detail.formId;
    var orderId = event.currentTarget.dataset.id;
    var ordescId = event.currentTarget.dataset.ordescId;
    var payDiffMoney = that.data.Info.payDiffMoney;
    console.log("ordescId=" + orderId);
    console.log("formId=" + formId);
    wx.checkSession({
      success: function () {
        //session 未过期，并且在本生命周期一直有效
        var tpcode = app.getWxCode();
        var tpid = app.getOpenId();
        //为保险起见，同时判断code跟openid是否有空值

        if (tpcode == null || tpcode.length < 1 || tpid == null || tpid.length < 1) {
          console.log("本地信息为空");
          //本地信息为空，重新登陆
          app.login(function (openid, userInfo, wxcode) {
            console.log(openid);
            util.wxpaydiff(app.api.wxpaydiff, wxcode, openid, payDiffMoney, orderId, formId);
          });
        } else {
          console.log(tpcode + "本地用户信息有效" + tpid);
          //本地用户信息有效
          util.wxpaydiff(app.api.wxpaydiff, tpcode, tpid, payDiffMoney, orderId, formId);
        }

      },
      fail: function () {
        console.log("重新登录");
        //登录态过期 重新登录
        app.login(function (openid, userInfo, wxcode) {
          util.wxpaydiff(app.api.wxpaydiff, wxcode, openid, payDiffMoney, orderId, formId);
        });
      }
    })
  }
})